@echo off
setlocal
:: constants

:: bootstrap
pushd %~dp0
call _configure.bat
popd

set export_path=%BRANCH_EXPORT_PATH%

:: start
set branch_name=%1

:: declare branch
:redefine_branch
if not defined branch_name (
	
	set /P branch_name=Enter branch name: 
	
	if not defined branch_name (
		
		goto :redefine_branch
		
	)

)

:: check if export path exist
:redefine_export_path
if not exist %export_path%\nul (

	echo unable to find tool in this branch %export_path%
	
	set /P export_path=Enter Export Path: 
	
	goto :redefine_export_path
	
)

:: check if SVN Client is available in %PATH%
echo Checking Available SVN Client ...
call :executable_exists %SVN_CLIENT_CLI%
if defined batch_error (
	echo %batch_error%
	echo SVN Client do not exist.
	goto :end
)

set SVN_FULL_BRANCH_URL=svn://%SVN_HOST%/%SVN_BRANCH_URL%/%SVN_BRANCH_DIR%/%branch_name%

:: export
call svn export %SVN_FULL_BRANCH_URL% "%export_path%\%branch_name%" --username %SVN_USER% --password %SVN_PASS%



goto :end

:show_usage
echo usage: xupdate [XML FILE]
goto :eof


::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Check if executable exists
::
:: usage: call :executable_exists [path]
:: 
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:executable_exists
set "batch_error="
setlocal
if [%1] == [] (
	set _error=No Executable File defined
) else (
	call where %1
	if not [%errorlevel%] == [0]  (
		set _error=Executable File %1 do not exist
	)
)

endlocal & call set batch_error=%_error%
if defined batch_error (
	exit /B 1
)
goto :eof






:end
endlocal